<template>
  <div class="yun-card" v-bind="$attrs" :style="style">
    <div class="yun-card-head">
      <div class="yun-card-title">
        <i></i>
        <span class="yun-title">{{ props.title }}</span>
      </div>
      <div class="yun-card-option">
        <slot name="card-option"></slot>
      </div>
    </div>
    <div class="yun-card-body">
      <slot></slot>
    </div>
  </div>
</template>

<script setup>
import { computed } from "vue"

const props = defineProps({
  title:{
    type:String,
    default:"标题"
  },
  width:{
    type:[String,Number],
    default:'100%'
  }
})
const style = computed(()=>{
  let width = props.width.includes("%")?props.width:props.width.includes("px")?props.width:props.width+"px"
  return `width:${width}`
})
</script>

<style lang="scss" scoped>
.yun-card{
  width:100%;
  height:auto;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 0 4px #efefef;
  overflow: hidden;
  .yun-card-head{
    width:100%;
    height:50px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--main-color);
    .yun-card-title{
      display: flex;
      align-items: center;
      color:#fff;
      font-size:16px;
      i{
        display: block;
        width:2px;
        height:16px;
        background: #fff;
        border-radius: 2px;
        margin-right:10px;
      }
    }
  }
  .yun-card-body{
    padding:15px;
  }
}
</style>